package com.ruoyi.web.controller.TiebaChat.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.web.controller.TiebaChat.domain.TiebaChat;
import com.ruoyi.web.controller.TiebaChat.mapper.TiebaChatMapper;
import com.ruoyi.web.controller.TiebaChat.service.ITiebaChatService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.utils.StringUtils;

import java.util.List;
import java.util.Map;


/**
 * 贴吧聊天Service业务层处理
 *
 * @author yong
 * @date 2025-03-09
 */
@Service
public class TiebaChatServiceImpl extends ServiceImpl<TiebaChatMapper, TiebaChat> implements ITiebaChatService {

    @Autowired
    private TiebaChatMapper tiebaChatMapper;

    /**
     * 查询贴吧聊天列表
     *
     * @param tiebaChat 贴吧聊天
     * @return 贴吧聊天
     */
    @Override
    public List<TiebaChat> selectTiebaChatList(TiebaChat tiebaChat) {
        List<TiebaChat> tiebaChatList = tiebaChatMapper.selectList(buildQueryWrapper(tiebaChat));
        return tiebaChatList;
    }

    @Override
    public List<TiebaChat> selectTiebaChatList2(TiebaChat tiebaChat) {
        List<TiebaChat> tiebaChatList = tiebaChatMapper.selectList(buildQueryWrapper2(tiebaChat));
        return tiebaChatList;
    }


    private LambdaQueryWrapper<TiebaChat> buildQueryWrapper(TiebaChat query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<TiebaChat> lqw = Wrappers.lambdaQuery();
//        lqw.eq(TiebaChat::getSenderId, query.getSenderId());
//        lqw.eq(TiebaChat::getReceiverId, query.getReceiverId());
        lqw.eq(TiebaChat::getUserId, query.getUserId());
        lqw.eq(TiebaChat::getUserOtherId, query.getUserOtherId());
//        lqw.eq(query.getDeptId() != null, TiebaChat::getDeptId, query.getDeptId());
//        lqw.eq(StringUtils.isNotBlank(query.getMessage()), TiebaChat::getMessage, query.getMessage());
//        lqw.eq(StringUtils.isNotBlank(query.getMessageType()), TiebaChat::getMessageType, query.getMessageType());
//        lqw.eq(StringUtils.isNotBlank(query.getStatus()), TiebaChat::getStatus, query.getStatus());
        lqw.orderByDesc(TiebaChat::getCreateTime);
        return lqw;
    }


    private LambdaQueryWrapper<TiebaChat> buildQueryWrapper2(TiebaChat query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<TiebaChat> lqw = Wrappers.lambdaQuery();
        lqw.orderByDesc(TiebaChat::getCreateTime);
        return lqw;
    }


}
